home *** CD-ROM | disk | FTP | other *** search
- /* #[info: */
- /************************************************************************
- * *
- * #### #### ##### # # ### #### ### *
- * # # # ### ## ## # # # *
- * # # # # # # ## # # # # *
- * ### # ## ### # # # # ### # *
- * # # # # # # # # # # *
- * # # # # # # # # # # *
- * #### #### # ###### # # ### #### ### *
- * *
- * Jan van der Steen *
- * *
- * Centre for Mathematics and Computer Science *
- * Amsterdam, the Netherlands *
- * *
- *----------------------------------------------------------------------*
- * File : sgf2misc.c *
- * Purpose : Read and convert a Smart Go Format file *
- * Version : 1.12 *
- * Modified: 2/14/93 13:39:07 *
- * Author : Jan van der Steen (jansteen@cwi.nl) *
- ************************************************************************/
- /* #]info: */
- /* #[README: */
-
- /*
- * A Mickey-Mouse Smart Go Format to LaTeX/SGF converter. It
- * is developed as a quick hack to convert the Otake-Kobayashi
- * Meijin game to a printable and rather portable document.
- * The converter doesn't have much knowledge about SGF format yet.
- * It's typically based on the SGF files as produced by IGS:
- *
- * (
- * ;
- * EVent[A game played on the Internet Go Server]
- * USer[Brought to you by the IGS program]
- * PlayerBlack[kobayashi]
- * BlackRanking[NR]
- * PlayerWhite[otake]
- * WhiteRanking[NR]
- * DaTe[1992-09-15]
- * GaMe[1]
- * VieW[]
- * SiZe[19]
- * GameName[(IGS) otake(W) vs kobayashi(B)]
- * PlaCe[IGS: Albuquerque, NM, USA 129.24.14.70 6969]
- * REsult[B+resign]
- * KoMi[0.000000]
- * BlacktimeLeft[0]
- * WhitetimeLeft[0]
- * ;
- * B[pd]
- * ;
- * W[dd]
- * C[
- * zhuge NR: okay, L3.
- * jjs NR: yeah, but i have oddive hour at 2pm
- * ]
- * ;
- * )
- *
- * Some general characteristics of the sgf2TeX convertion
- * ------------------------------------------------------
- * 1. It only recognise moves and kibitz comments.
- * 2. It exchanges move and kibitz.
- * They are written in the sgf file in the wrong order
- * (i.e. first move then kibitz).
- * 3. Merge moves without kibitz in one diagram.
- * 4. Generate one kibitz label for consequetive kibitzes.
- */
-
- /* #]README: */
- /* #[include: */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "gogame.h"
- #include "sgfread.h"
- #include "game2tex.h"
- #include "game2eps.h"
- #include "game2sgf.h"
- #include "tools.h"
- #include "sysdep.h"
-
- /* #]include: */
- /* #[global: */
-
- int optind = 1; /* index into argv vector */
- int caching = 0; /* Caching mode */
- int textout = 1; /* Emit the text */
- int statout = 0; /* Emit the kibitz stats */
- int coords = 1; /* Print coordinates */
- char * program = "sgf2misc"; /* Program name */
- int verbose = 0; /* Verbose mode */
- EPSFINFO epsf; /* The eps filename/directory */
- /*
- * The next variable decides how to solve the Go diagram issue:
- *
- * DEVICE_EPS Diagrams are handled by epsf PostScript inclusion
- * DEVICE_TEX Diagrams are handled by a special TeX Go font
- */
- int prn_dev = DEVICE_EPS; /* DEVICE_{EPS,TEX} */
-
- /*
- * The next variables allow the user to specify an output list
- * of figures/diagrams
- */
- int figlist[MAXNUM]; /* Figure list */
- int dialist[MAXNUM]; /* Diagram list */
- int user_figs = 0; /* Users fig list? */
- int user_dias = 0; /* Users dia list? */
-
- /* #]global: */
- /* #[prototype: */
-
- #ifdef __STDC__
- # define PROTO(s) s
- #else
- # define PROTO(s) ()
- #endif
-
- void main PROTO((int argc, char **argv));
- static char * epsf_filename PROTO((char *fullpathname));
-
- #undef PROTO
-
- /* #]prototype: */
-
- /* #[main: */
-
- void
- main(argc, argv)
- int argc;
- char **argv;
- {
- GOGAME *gogame = (GOGAME *) 0; /* The complete game */
- FILE *fp = stdin; /* The read channel */
-
- #if defined(ATARI)
- argv[0] = program;
- #else
- program = argv[0];
- #endif
- getoptions(argc, argv);
-
- /*
- * Process the Smart Go Format file
- */
- if (optind < argc) {
- if ((fp = fopen(argv[optind], "r")) == (FILE *) 0) {
- fprintf(stderr, "Can't open \"%s\"\n", argv[optind]);
- exit(1);
- }
- epsf.eps_name = epsf_filename(argv[optind]);
- } else
- epsf.eps_name = "stdin";
-
- if ((gogame = sgf_read(fp)) != (GOGAME *) 0) {
- if (user_figs) list2tex(gogame);
- else game2tex(gogame);
- game_free (gogame);
- }
- exit(0);
- }
-
- /* #]main: */
- /* #[epsf_filename: */
-
- static char *
- epsf_filename(fullpathname)
- /*
- * Look for suffix and delete it (detructive on source!)
- * Next, return the basename of the file.
- */
- char *fullpathname;
- {
- char *s = fullpathname;
-
- /*
- * First delete the suffix
- */
- while (*s) s++;
- while (s > fullpathname && *s != PATHSEP && *s != '.') s--;
- /*
- * We never want to remove the path seperator
- */
- if (*s != PATHSEP) *s = 0;
-
- /*
- * Next, return the basename
- */
- while (s > fullpathname && *s != PATHSEP) s--;
- if (*s == PATHSEP) s++;
-
- return s;
- }
-
- /* #]epsf_filename: */
-